﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data.SqlClient;
using System.Data;
using System.Timers;
using System.Windows.Threading;
using System.ComponentModel;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;
using System.IO;

namespace TAMSUP
{
    public partial class topWindow : Window
    {
        public static SqlDataAdapter da;
        public static cautionWindow caution;
        public static cp contactperson;
        public static cp rencpemb;
        public static detailReklame detailRek;
        public static setting set;
        public static string username;
        public static string role;
        public static Server srvr;
        private string DBpath = "\\\\SERVER-PC\\Users\\Public\\Documents";
        public int tabel;
        public int rek;
        public int time = 14;

        public bool close = false;

        public const int REKLAME = 0;
        public const int PENYEWAAN = 1;
        public const int PEMBAYARAN = 2;
        public const int GUDANG = 3;
        public const int PEMBELIAN = 4;
        public const int PEMAKAIAN = 5;
        public const int PENGGUNA = 6;
        public const int CP = 7;
        public const int RENCANAPEMBAYARAN = 8;

        public bool[] filter = new bool[9];
        public bool isFilter = false;

        DispatcherTimer dispatcherTimer = new DispatcherTimer();

        public DataGrid dr;

        public topWindow()
        {
            InitializeComponent();
            close = false;
        }

        public void FillData()
        {
            if (role.Equals("Keuangan"))
            {
                Gudang.Visibility = System.Windows.Visibility.Collapsed;
                Laporan_Pemakaian.Visibility = System.Windows.Visibility.Collapsed;
                Laporan_Pembelian.Visibility = System.Windows.Visibility.Collapsed;
                Pengguna.Visibility = System.Windows.Visibility.Collapsed;
                Ubah_.Visibility = System.Windows.Visibility.Collapsed;
                Hapus_.Visibility = System.Windows.Visibility.Collapsed;
                Tambah_Baru.Visibility = System.Windows.Visibility.Collapsed;
                Backup_.Visibility = System.Windows.Visibility.Collapsed;
                Restore_.Visibility = System.Windows.Visibility.Collapsed;
            }
            else if (role.Equals("Pergudangan"))
            {
                Reklame.Visibility = System.Windows.Visibility.Collapsed;
                Penyewaan.Visibility = System.Windows.Visibility.Collapsed;
                Pembayaran.Visibility = System.Windows.Visibility.Collapsed;
                Pengguna.Visibility = System.Windows.Visibility.Collapsed;
                Ubah_.Visibility = System.Windows.Visibility.Collapsed;
                Hapus_.Visibility = System.Windows.Visibility.Collapsed;
                Tambah_Baru.Visibility = System.Windows.Visibility.Collapsed;
                Backup_.Visibility = System.Windows.Visibility.Collapsed;
                Restore_.Visibility = System.Windows.Visibility.Collapsed;
                Reminder.Visibility = System.Windows.Visibility.Collapsed;
            }
            else if (role.Equals("Marketing"))
            {
                Gudang.Visibility = System.Windows.Visibility.Collapsed;
                Laporan_Pemakaian.Visibility = System.Windows.Visibility.Collapsed;
                Laporan_Pembelian.Visibility = System.Windows.Visibility.Collapsed;
                Penyewaan.Visibility = System.Windows.Visibility.Collapsed;
                Pembayaran.Visibility = System.Windows.Visibility.Collapsed;
                Pengguna.Visibility = System.Windows.Visibility.Collapsed;
                Ubah_.Visibility = System.Windows.Visibility.Collapsed;
                Hapus_.Visibility = System.Windows.Visibility.Collapsed;
                Tambah_Baru.Visibility = System.Windows.Visibility.Collapsed;
                Backup_.Visibility = System.Windows.Visibility.Collapsed;
                Restore_.Visibility = System.Windows.Visibility.Collapsed;
                Reklame_Disewa.Visibility = System.Windows.Visibility.Collapsed;
                Semua_Reklame.Visibility = System.Windows.Visibility.Collapsed;
                Reminder.Visibility = System.Windows.Visibility.Collapsed;
            }
            label3.Content = username + "[" + role + "]";
            label6.Content = "";
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            caution = new cautionWindow();
            caution.Visibility = System.Windows.Visibility.Hidden;

            set = new setting();
            set.Visibility = System.Windows.Visibility.Hidden;

            tabel = -1;
        }

        private void helpButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                System.Diagnostics.Process.Start(System.AppDomain.CurrentDomain.BaseDirectory + "\\help\\TAMSGUIDE.chm");
            }
            catch (Win32Exception w32e)
            {
                MessageBox.Show("File help tidak tersedia.\nSilakan periksa : " + System.AppDomain.CurrentDomain.BaseDirectory + "help\\TAMSGUIDE.chm");
            }
        }

        private void loginButton_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void TambahBaru(object sender, RoutedEventArgs e)
        {
            if (dataGrid1.Visibility == System.Windows.Visibility.Visible)
            {
                if (tabel == REKLAME)
                {
                    form addForm = new form();
                    addForm.Visibility = System.Windows.Visibility.Visible;
                }
                else if (tabel == PENYEWAAN)
                {
                    penyewaan addForm = new penyewaan();
                    addForm.Visibility = System.Windows.Visibility.Visible;
                }
                else if (tabel == PEMBELIAN)
                {
                    LaporanPembelianForm pem = new LaporanPembelianForm();
                    pem.Visibility = System.Windows.Visibility.Visible;
                }
                else if (tabel == PEMBAYARAN)
                {
                    PembayaranForm pem = new PembayaranForm();
                    pem.Visibility = System.Windows.Visibility.Visible;
                }
                else if (tabel == PEMAKAIAN)
                {
                    LaporanPemakaianBarang pem = new LaporanPemakaianBarang();
                    pem.Visibility = System.Windows.Visibility.Visible;
                }
                else if (tabel == GUDANG)
                {
                    addBarang pem = new addBarang();
                    pem.Visibility = System.Windows.Visibility.Visible;
                }
                else if (tabel == PENGGUNA)
                {
                    pengguna pem = new pengguna();
                    pem.Visibility = System.Windows.Visibility.Visible;
                }
            }
            else
            {
                MessageBox.Show("Pilih salah satu tabel terlebih dahulu", "Error: No Table");
            }
        }

        private void Hapus(object sender, RoutedEventArgs e)
        {
            if (dataGrid1.SelectedIndex >= 0)
            {
                dr = dataGrid1;
                if (tabel == PEMBELIAN)
                {
                    delete del = new delete(tabel, ((DataRowView)(dataGrid1.SelectedItem)).Row.ItemArray.ElementAt(0).ToString(), ((DataRowView)(dataGrid1.SelectedItem)).Row.ItemArray.ElementAt(1).ToString());
                    del.Visibility = System.Windows.Visibility.Visible;
                }
                else if (tabel == PEMAKAIAN)
                {
                    delete del = new delete(tabel, ((DataRowView)(dataGrid1.SelectedItem)).Row.ItemArray.ElementAt(0).ToString(), ((DataRowView)(dataGrid1.SelectedItem)).Row.ItemArray.ElementAt(4).ToString());
                    del.Visibility = System.Windows.Visibility.Visible;
                }
                else
                {
                    delete del = new delete(tabel, ((DataRowView)(dataGrid1.SelectedItem)).Row.ItemArray.ElementAt(0).ToString());
                    del.Visibility = System.Windows.Visibility.Visible;
                }
            }
            else
            {
                MessageBox.Show("Anda harus memilih salah satu data", "Error: Null Selection");
            }
        }

        private void Ubah(object sender, RoutedEventArgs e)
        {
            if (dataGrid1.SelectedIndex >= 0)
            {
                if (tabel == REKLAME)
                {
                    form addForm = new form(((DataRowView)(dataGrid1.SelectedItem)).Row.ItemArray.ElementAt(0).ToString());
                    addForm.Visibility = System.Windows.Visibility.Visible;
                }
                else if (tabel == PENYEWAAN)
                {
                    penyewaan addForm = new penyewaan(((DataRowView)(dataGrid1.SelectedItem)).Row.ItemArray.ElementAt(0).ToString());
                    addForm.Visibility = System.Windows.Visibility.Visible;
                }
                else if (tabel == PEMBELIAN)
                {
                    LaporanPembelianForm pem = new LaporanPembelianForm(((DataRowView)(dataGrid1.SelectedItem)).Row.ItemArray.ElementAt(0).ToString(), ((DataRowView)(dataGrid1.SelectedItem)).Row.ItemArray.ElementAt(1).ToString());
                    pem.Visibility = System.Windows.Visibility.Visible;
                }
                else if (tabel == PEMBAYARAN)
                {
                    PembayaranForm pem = new PembayaranForm(((DataRowView)(dataGrid1.SelectedItem)).Row.ItemArray.ElementAt(0).ToString());
                    pem.Visibility = System.Windows.Visibility.Visible;
                }
                else if (tabel == PEMAKAIAN)
                {
                    LaporanPemakaianBarang pem = new LaporanPemakaianBarang(((DataRowView)(dataGrid1.SelectedItem)).Row.ItemArray.ElementAt(0).ToString(), ((DataRowView)(dataGrid1.SelectedItem)).Row.ItemArray.ElementAt(1).ToString());
                    pem.Visibility = System.Windows.Visibility.Visible;
                }
                else if (tabel == GUDANG)
                {
                    addBarang pem = new addBarang(((DataRowView)(dataGrid1.SelectedItem)).Row.ItemArray.ElementAt(0).ToString());
                    pem.Visibility = System.Windows.Visibility.Visible;
                }
                else if (tabel == PENGGUNA)
                {
                    pengguna pem = new pengguna(((DataRowView)(dataGrid1.SelectedItem)).Row.ItemArray.ElementAt(0).ToString());
                    pem.Visibility = System.Windows.Visibility.Visible;
                }
            }
            else
            {
                MessageBox.Show("Anda harus memilih salah satu data", "Error: Null Selection");
            }
        }

        private void Backup(object sender, RoutedEventArgs e)
        {
            try
            {
                int i = 0;
                while (homeWindow.connectionString[i + 12] != ';')
                {
                    i++;
                }
                string s = homeWindow.connectionString.Substring(12, i);
                Console.WriteLine(s);
                Console.WriteLine(DBpath);
                ServerConnection srvConn = new ServerConnection(s);
                srvr = new Server(srvConn);
                if (srvr != null)
                {
                    try
                    {

                        //Use this line if you have already created a backup file.
                        File.Delete(DBpath + "\\backupTAM.bak");
                        this.Cursor = Cursors.Wait;
                        // If the user has chosen a path where to save the backup file
                        // Create a new backup operation
                        Backup bkpDatabase = new Backup();
                        // Set the backup type to a database backup
                        bkpDatabase.Action = BackupActionType.Database;
                        // Set the database that we want to perform a backup on
                        int j = i + 29;
                        int k = 0;
                        while (homeWindow.connectionString[k + j] != ';')
                        {
                            k++;
                        }
                        s = homeWindow.connectionString.Substring(j, k);
                        String t = "\"";
                        s = s.Trim(t.ToCharArray());
                        Console.WriteLine(s);
                        bkpDatabase.Database = s;
                        // Set the backup device to a file
                        BackupDeviceItem bkpDevice = new BackupDeviceItem(DBpath + "\\backupTAM.bak", DeviceType.File);
                        // Add the backup device to the backup
                        bkpDatabase.Devices.Add(bkpDevice);
                        // Perform the backup
                        bkpDatabase.SqlBackup(srvr);
                        MessageBox.Show("Backup of Database " + s + " successfully created", "Server", MessageBoxButton.OK, MessageBoxImage.Warning);
                        refresh();
                    }
                    catch (Exception es )
                    {
                        MessageBox.Show("ERROR: An error ocurred while backing up DataBase" + es, "Server Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    finally
                    {
                        this.Cursor = Cursors.Arrow;
                    }
                }
                else
                {
                    MessageBox.Show("ERROR: A connection to a SQL server was not established.", "Server", MessageBoxButton.OK, MessageBoxImage.Error);
                    this.Cursor = Cursors.Arrow;
                }
            }
            catch (Exception es)
            {
                MessageBox.Show("ERROR: A connection to a SQL server was not established." + es, "Server", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

        private void Restore(object sender, RoutedEventArgs e)
        {
            int i = 0;
            while (homeWindow.connectionString[i + 12] != ';')
            {
                i++;
            }
            string s = homeWindow.connectionString.Substring(12, i);
            Console.WriteLine(s);
            Console.WriteLine(DBpath);
            ServerConnection srvConn = new ServerConnection(s);
            srvr = new Server(srvConn);
            if (srvr != null)
            {
                try
                {
                    caution.Close();
                    set.Close();
                    if (rencpemb != null)
                    {
                        rencpemb.Close();
                    }
                    if (contactperson != null)
                    {
                        contactperson.Close();
                    }
                    //Con.Dispose();
                    //Con = null;
                    this.Cursor = Cursors.Wait;
                    // If the user has chosen the file from which he wants the database to be restored
                    // Create a new database restore operation
                    Restore rstDatabase = new Restore();
                    // Set the restore type to a database restore
                    rstDatabase.Action = RestoreActionType.Database;
                    // Set the database that we want to perform the restore on
                    int j = i + 29;
                    int k = 0;
                    while (homeWindow.connectionString[k + j] != ';')
                    {
                        k++;
                    }
                    s = homeWindow.connectionString.Substring(j, k);
                    String t = "\"";
                    s = s.Trim(t.ToCharArray());
                    Console.WriteLine(s);
                    rstDatabase.Database = s;
                    homeWindow.Con.Open();
                    SqlCommand cmd = new SqlCommand("use master alter database [" + s + "] set offline", homeWindow.Con);
                    cmd.ExecuteNonQuery();
                    homeWindow.Con.Close();
                    // Set the backup device from which we want to restore, to a file
                    BackupDeviceItem bkpDevice = new BackupDeviceItem(DBpath + "\\backupTAM.bak", DeviceType.File);
                    // Add the backup device to the restore type
                    rstDatabase.Devices.Add(bkpDevice);
                    // If the database already exists, replace it
                    rstDatabase.ReplaceDatabase = true;
                    rstDatabase.SqlRestore(srvr);
                    MessageBox.Show("Database " + s + " succefully restored", "Server", MessageBoxButton.OK, MessageBoxImage.Information);
                    homeWindow.Con.Open();
                    cmd = new SqlCommand("use master alter database [" + s + "] set online", homeWindow.Con);
                    cmd.ExecuteNonQuery();
                    homeWindow.Con.Close();
                    refresh();
                }
                catch (Exception x)
                {
                    MessageBox.Show("ERROR: An error ocurred while restoring the database" + x, "Restore Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    homeWindow.Con.Open();
                    SqlCommand cmd = new SqlCommand("use master alter database [" + s + "] set online", homeWindow.Con);
                    cmd.ExecuteNonQuery();
                    homeWindow.Con.Close();
                }
                finally
                {
                    this.Cursor = Cursors.Arrow;
                }
            }
            else
            {
                MessageBox.Show("ERROR: A connection to a SQL server was not established.", "Server", MessageBoxButton.OK, MessageBoxImage.Error);
                this.Cursor = Cursors.Arrow;
            }
        }

        private void chooseATable()
        {
            if (dataGrid1.Visibility == System.Windows.Visibility.Hidden)
            {
                image1.Visibility = System.Windows.Visibility.Collapsed;
                dataGrid1.Visibility = System.Windows.Visibility.Visible;
            }
        }

        private void LihatSemuaReklame(object sender, RoutedEventArgs e)
        {
            chooseATable();
            if (tabel != REKLAME)
            {
                isFilter = false;
            }
            tabel = REKLAME;
            if (role.Equals("Keuangan"))
            {
                Ubah_.Visibility = System.Windows.Visibility.Collapsed;
                Hapus_.Visibility = System.Windows.Visibility.Collapsed;
                Tambah_Baru.Visibility = System.Windows.Visibility.Collapsed;
                Backup_.Visibility = System.Windows.Visibility.Collapsed;
                Restore_.Visibility = System.Windows.Visibility.Collapsed;
            }
            else if (role.Equals("Pergudangan"))
            {
                Ubah_.Visibility = System.Windows.Visibility.Collapsed;
                Hapus_.Visibility = System.Windows.Visibility.Collapsed;
                Tambah_Baru.Visibility = System.Windows.Visibility.Collapsed;
                Backup_.Visibility = System.Windows.Visibility.Collapsed;
                Restore_.Visibility = System.Windows.Visibility.Collapsed;
            }
            else if (role.Equals("Marketing"))
            {
                Ubah_.Visibility = System.Windows.Visibility.Collapsed;
                Hapus_.Visibility = System.Windows.Visibility.Collapsed;
                Tambah_Baru.Visibility = System.Windows.Visibility.Collapsed;
                Backup_.Visibility = System.Windows.Visibility.Collapsed;
                Restore_.Visibility = System.Windows.Visibility.Collapsed;
            }
            rek = 0;
            refresh();
        }

        private void LihatReklameAktif(object sender, RoutedEventArgs e)
        {
            chooseATable();
            if (tabel != REKLAME)
            {
                isFilter = false;
            }
            tabel = REKLAME;
            if (role.Equals("Keuangan"))
            {
                Ubah_.Visibility = System.Windows.Visibility.Collapsed;
                Hapus_.Visibility = System.Windows.Visibility.Collapsed;
                Tambah_Baru.Visibility = System.Windows.Visibility.Collapsed;
                Backup_.Visibility = System.Windows.Visibility.Collapsed;
                Restore_.Visibility = System.Windows.Visibility.Collapsed;
            }
            else if (role.Equals("Pergudangan"))
            {
                Ubah_.Visibility = System.Windows.Visibility.Collapsed;
                Hapus_.Visibility = System.Windows.Visibility.Collapsed;
                Tambah_Baru.Visibility = System.Windows.Visibility.Collapsed;
                Backup_.Visibility = System.Windows.Visibility.Collapsed;
                Restore_.Visibility = System.Windows.Visibility.Collapsed;
            }
            else if (role.Equals("Marketing"))
            {
                Ubah_.Visibility = System.Windows.Visibility.Collapsed;
                Hapus_.Visibility = System.Windows.Visibility.Collapsed;
                Tambah_Baru.Visibility = System.Windows.Visibility.Collapsed;
                Backup_.Visibility = System.Windows.Visibility.Collapsed;
                Restore_.Visibility = System.Windows.Visibility.Collapsed;
            }
            rek = 1;
            refresh();
        }

        private void LihatReklameDisewa(object sender, RoutedEventArgs e)
        {
            chooseATable();
            if (tabel != REKLAME)
            {
                isFilter = false;
            }
            tabel = REKLAME;
            if (role.Equals("Keuangan"))
            {
                Ubah_.Visibility = System.Windows.Visibility.Collapsed;
                Hapus_.Visibility = System.Windows.Visibility.Collapsed;
                Tambah_Baru.Visibility = System.Windows.Visibility.Collapsed;
                Backup_.Visibility = System.Windows.Visibility.Collapsed;
                Restore_.Visibility = System.Windows.Visibility.Collapsed;
            }
            else if (role.Equals("Pergudangan"))
            {
                Ubah_.Visibility = System.Windows.Visibility.Collapsed;
                Hapus_.Visibility = System.Windows.Visibility.Collapsed;
                Tambah_Baru.Visibility = System.Windows.Visibility.Collapsed;
                Backup_.Visibility = System.Windows.Visibility.Collapsed;
                Restore_.Visibility = System.Windows.Visibility.Collapsed;
            }
            else if (role.Equals("Marketing"))
            {
                Ubah_.Visibility = System.Windows.Visibility.Collapsed;
                Hapus_.Visibility = System.Windows.Visibility.Collapsed;
                Tambah_Baru.Visibility = System.Windows.Visibility.Collapsed;
                Backup_.Visibility = System.Windows.Visibility.Collapsed;
                Restore_.Visibility = System.Windows.Visibility.Collapsed;
            }
            rek = 2;
            refresh();
        }

        private void LihatSemuaPenyewaan(object sender, RoutedEventArgs e)
        {
            chooseATable();
            if (tabel != PENYEWAAN)
            {
                isFilter = false;
            }
            tabel = PENYEWAAN;
            if (role.Equals("Keuangan"))
            {
                Ubah_.Visibility = System.Windows.Visibility.Visible;
                Hapus_.Visibility = System.Windows.Visibility.Visible;
                Tambah_Baru.Visibility = System.Windows.Visibility.Visible;
                Backup_.Visibility = System.Windows.Visibility.Collapsed;
                Restore_.Visibility = System.Windows.Visibility.Collapsed;
            }
            else if (role.Equals("Pergudangan"))
            {
                Ubah_.Visibility = System.Windows.Visibility.Collapsed;
                Hapus_.Visibility = System.Windows.Visibility.Collapsed;
                Tambah_Baru.Visibility = System.Windows.Visibility.Collapsed;
                Backup_.Visibility = System.Windows.Visibility.Collapsed;
                Restore_.Visibility = System.Windows.Visibility.Collapsed;
            }
            else if (role.Equals("Marketing"))
            {
                Ubah_.Visibility = System.Windows.Visibility.Collapsed;
                Hapus_.Visibility = System.Windows.Visibility.Collapsed;
                Tambah_Baru.Visibility = System.Windows.Visibility.Collapsed;
                Backup_.Visibility = System.Windows.Visibility.Collapsed;
                Restore_.Visibility = System.Windows.Visibility.Collapsed;
            }
            rek = 0;
            refresh();
        }

        private void LihatPenyewaanAktif(object sender, RoutedEventArgs e)
        {
            chooseATable();
            if (tabel != PENYEWAAN)
            {
                isFilter = false;
            }
            tabel = PENYEWAAN;
            if (role.Equals("Keuangan"))
            {
                Ubah_.Visibility = System.Windows.Visibility.Visible;
                Hapus_.Visibility = System.Windows.Visibility.Visible;
                Tambah_Baru.Visibility = System.Windows.Visibility.Visible;
                Backup_.Visibility = System.Windows.Visibility.Collapsed;
                Restore_.Visibility = System.Windows.Visibility.Collapsed;
            }
            else if (role.Equals("Pergudangan"))
            {
                Ubah_.Visibility = System.Windows.Visibility.Collapsed;
                Hapus_.Visibility = System.Windows.Visibility.Collapsed;
                Tambah_Baru.Visibility = System.Windows.Visibility.Collapsed;
                Backup_.Visibility = System.Windows.Visibility.Collapsed;
                Restore_.Visibility = System.Windows.Visibility.Collapsed;
            }
            else if (role.Equals("Marketing"))
            {
                Ubah_.Visibility = System.Windows.Visibility.Collapsed;
                Hapus_.Visibility = System.Windows.Visibility.Collapsed;
                Tambah_Baru.Visibility = System.Windows.Visibility.Collapsed;
                Backup_.Visibility = System.Windows.Visibility.Collapsed;
                Restore_.Visibility = System.Windows.Visibility.Collapsed;
            }
            rek = 1;
            refresh();
        }

        private void LihatPenyewaanLampau(object sender, RoutedEventArgs e)
        {
            chooseATable();
            if (tabel != PENYEWAAN)
            {
                isFilter = false;
            }
            tabel = PENYEWAAN;
            if (role.Equals("Keuangan"))
            {
                Ubah_.Visibility = System.Windows.Visibility.Visible;
                Hapus_.Visibility = System.Windows.Visibility.Visible;
                Tambah_Baru.Visibility = System.Windows.Visibility.Visible;
                Backup_.Visibility = System.Windows.Visibility.Collapsed;
                Restore_.Visibility = System.Windows.Visibility.Collapsed;
            }
            else if (role.Equals("Pergudangan"))
            {
                Ubah_.Visibility = System.Windows.Visibility.Collapsed;
                Hapus_.Visibility = System.Windows.Visibility.Collapsed;
                Tambah_Baru.Visibility = System.Windows.Visibility.Collapsed;
                Backup_.Visibility = System.Windows.Visibility.Collapsed;
                Restore_.Visibility = System.Windows.Visibility.Collapsed;
            }
            else if (role.Equals("Marketing"))
            {
                Ubah_.Visibility = System.Windows.Visibility.Collapsed;
                Hapus_.Visibility = System.Windows.Visibility.Collapsed;
                Tambah_Baru.Visibility = System.Windows.Visibility.Collapsed;
                Backup_.Visibility = System.Windows.Visibility.Collapsed;
                Restore_.Visibility = System.Windows.Visibility.Collapsed;
            }
            rek = 2;
            refresh();
        }

        private void LihatPembayaran(object sender, RoutedEventArgs e)
        {
            chooseATable();
            if (tabel != PEMBAYARAN)
            {
                isFilter = false;
            }
            tabel = PEMBAYARAN;
            if (role.Equals("Keuangan"))
            {
                Ubah_.Visibility = System.Windows.Visibility.Visible;
                Hapus_.Visibility = System.Windows.Visibility.Visible;
                Tambah_Baru.Visibility = System.Windows.Visibility.Visible;
                Backup_.Visibility = System.Windows.Visibility.Collapsed;
                Restore_.Visibility = System.Windows.Visibility.Collapsed;
            }
            else if (role.Equals("Pergudangan"))
            {
                Ubah_.Visibility = System.Windows.Visibility.Collapsed;
                Hapus_.Visibility = System.Windows.Visibility.Collapsed;
                Tambah_Baru.Visibility = System.Windows.Visibility.Collapsed;
                Backup_.Visibility = System.Windows.Visibility.Collapsed;
                Restore_.Visibility = System.Windows.Visibility.Collapsed;
            }
            else if (role.Equals("Marketing"))
            {
                Ubah_.Visibility = System.Windows.Visibility.Collapsed;
                Hapus_.Visibility = System.Windows.Visibility.Collapsed;
                Tambah_Baru.Visibility = System.Windows.Visibility.Collapsed;
                Backup_.Visibility = System.Windows.Visibility.Collapsed;
                Restore_.Visibility = System.Windows.Visibility.Collapsed;
            }
            refresh();
        }

        private void LihatBarang(object sender, RoutedEventArgs e)
        {
            chooseATable();
            if (tabel != GUDANG)
            {
                isFilter = false;
            }
            tabel = GUDANG;
            if (role.Equals("Keuangan"))
            {
                Ubah_.Visibility = System.Windows.Visibility.Collapsed;
                Hapus_.Visibility = System.Windows.Visibility.Collapsed;
                Tambah_Baru.Visibility = System.Windows.Visibility.Collapsed;
                Backup_.Visibility = System.Windows.Visibility.Collapsed;
                Restore_.Visibility = System.Windows.Visibility.Collapsed;
            }
            else if (role.Equals("Pergudangan"))
            {
                Ubah_.Visibility = System.Windows.Visibility.Visible;
                Hapus_.Visibility = System.Windows.Visibility.Visible;
                Tambah_Baru.Visibility = System.Windows.Visibility.Visible;
                Backup_.Visibility = System.Windows.Visibility.Collapsed;
                Restore_.Visibility = System.Windows.Visibility.Collapsed;
            }
            else if (role.Equals("Marketing"))
            {
                Ubah_.Visibility = System.Windows.Visibility.Collapsed;
                Hapus_.Visibility = System.Windows.Visibility.Collapsed;
                Tambah_Baru.Visibility = System.Windows.Visibility.Collapsed;
                Backup_.Visibility = System.Windows.Visibility.Collapsed;
                Restore_.Visibility = System.Windows.Visibility.Collapsed;
            }
            refresh();
        }

        private void LihatLapPembelian(object sender, RoutedEventArgs e)
        {
            chooseATable();
            if (tabel != PEMBELIAN)
            {
                isFilter = false;
            }
            tabel = PEMBELIAN;
            if (role.Equals("Keuangan"))
            {
                Ubah_.Visibility = System.Windows.Visibility.Collapsed;
                Hapus_.Visibility = System.Windows.Visibility.Collapsed;
                Tambah_Baru.Visibility = System.Windows.Visibility.Collapsed;
                Backup_.Visibility = System.Windows.Visibility.Collapsed;
                Restore_.Visibility = System.Windows.Visibility.Collapsed;
            }
            else if (role.Equals("Pergudangan"))
            {
                Ubah_.Visibility = System.Windows.Visibility.Visible;
                Hapus_.Visibility = System.Windows.Visibility.Visible;
                Tambah_Baru.Visibility = System.Windows.Visibility.Visible;
                Backup_.Visibility = System.Windows.Visibility.Collapsed;
                Restore_.Visibility = System.Windows.Visibility.Collapsed;
            }
            else if (role.Equals("Marketing"))
            {
                Ubah_.Visibility = System.Windows.Visibility.Collapsed;
                Hapus_.Visibility = System.Windows.Visibility.Collapsed;
                Tambah_Baru.Visibility = System.Windows.Visibility.Collapsed;
                Backup_.Visibility = System.Windows.Visibility.Collapsed;
                Restore_.Visibility = System.Windows.Visibility.Collapsed;
            }
            refresh();
        }

        private void LihatLapPemakaian(object sender, RoutedEventArgs e)
        {
            chooseATable();
            if (tabel != PEMAKAIAN)
            {
                isFilter = false;
            }
            tabel = PEMAKAIAN;
            if (role.Equals("Keuangan"))
            {
                Ubah_.Visibility = System.Windows.Visibility.Collapsed;
                Hapus_.Visibility = System.Windows.Visibility.Collapsed;
                Tambah_Baru.Visibility = System.Windows.Visibility.Collapsed;
                Backup_.Visibility = System.Windows.Visibility.Collapsed;
                Restore_.Visibility = System.Windows.Visibility.Collapsed;
            }
            else if (role.Equals("Pergudangan"))
            {
                Ubah_.Visibility = System.Windows.Visibility.Visible;
                Hapus_.Visibility = System.Windows.Visibility.Visible;
                Tambah_Baru.Visibility = System.Windows.Visibility.Visible;
                Backup_.Visibility = System.Windows.Visibility.Collapsed;
                Restore_.Visibility = System.Windows.Visibility.Collapsed;
            }
            else if (role.Equals("Marketing"))
            {
                Ubah_.Visibility = System.Windows.Visibility.Collapsed;
                Hapus_.Visibility = System.Windows.Visibility.Collapsed;
                Tambah_Baru.Visibility = System.Windows.Visibility.Collapsed;
                Backup_.Visibility = System.Windows.Visibility.Collapsed;
                Restore_.Visibility = System.Windows.Visibility.Collapsed;
            }
            refresh();
        }

        private void LihatPengguna(object sender, RoutedEventArgs e)
        {
            chooseATable();
            if (tabel != PENGGUNA)
            {
                isFilter = false;
            }
            tabel = PENGGUNA;
            if (role.Equals("Keuangan"))
            {
                Ubah_.Visibility = System.Windows.Visibility.Collapsed;
                Hapus_.Visibility = System.Windows.Visibility.Collapsed;
                Tambah_Baru.Visibility = System.Windows.Visibility.Collapsed;
                Backup_.Visibility = System.Windows.Visibility.Collapsed;
                Restore_.Visibility = System.Windows.Visibility.Collapsed;
            }
            else if (role.Equals("Pergudangan"))
            {
                Ubah_.Visibility = System.Windows.Visibility.Collapsed;
                Hapus_.Visibility = System.Windows.Visibility.Collapsed;
                Tambah_Baru.Visibility = System.Windows.Visibility.Collapsed;
                Backup_.Visibility = System.Windows.Visibility.Collapsed;
                Restore_.Visibility = System.Windows.Visibility.Collapsed;
            }
            else if (role.Equals("Marketing"))
            {
                Ubah_.Visibility = System.Windows.Visibility.Collapsed;
                Hapus_.Visibility = System.Windows.Visibility.Collapsed;
                Tambah_Baru.Visibility = System.Windows.Visibility.Collapsed;
                Backup_.Visibility = System.Windows.Visibility.Collapsed;
                Restore_.Visibility = System.Windows.Visibility.Collapsed;
            }
            refresh();
        }

        private void ReminderWindow(object sender, RoutedEventArgs e)
        {
            if (caution.IsActive == false) {
                caution.Activate();
                caution.Visibility = System.Windows.Visibility.Visible;
            }
            else
            {
                caution.Visibility = System.Windows.Visibility.Visible;
            }
        }

        private void SettingWindow(object sender, RoutedEventArgs e)
        {
            if (tabel != GUDANG && tabel != PENGGUNA && tabel != -1)
            {
                if (set.IsActive == false)
                {
                    set.Activate();
                    set.Visibility = System.Windows.Visibility.Visible;
                }
                else
                {
                    set.Visibility = System.Windows.Visibility.Visible;
                }
            }
            else
            {
                MessageBox.Show("Anda tidak dapat melakukan setting pada tabel ini.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }

        private void dataGridDetail_Click(object sender, RoutedEventArgs e)
        {
            if (dataGrid1.SelectedIndex >= 0)
            {
                if (tabel == PENYEWAAN)
                {
                    if (dataGrid1.SelectedIndex >= 0)
                    {
                        rencpemb = new cp(((DataRowView)(dataGrid1.SelectedItem)).Row.ItemArray.ElementAt(0).ToString(), ((DataRowView)(dataGrid1.SelectedItem)).Row.ItemArray.ElementAt(1).ToString(), 1);
                        rencpemb.Visibility = System.Windows.Visibility.Visible;
                    }
                    else
                    {
                        MessageBox.Show("Anda harus memilih salah satu data", "Error: Null Selection");
                    }
                }
                else if (tabel == REKLAME)
                {
                    if (dataGrid1.SelectedIndex >= 0)
                    {
                        try
                        {
                            homeWindow.Con.Open();
                            string myPath = ((DataRowView)(dataGrid1.SelectedItem)).Row.ItemArray.ElementAt(0).ToString();
                            da = new SqlDataAdapter("select PathGambar from Reklame where ID_Reklame = '" + myPath + "'", homeWindow.Con);
                            DataSet ds = new DataSet();
                            da.Fill(ds, "Daftar Path");
                            myPath = ds.Tables["Daftar Path"].Rows[0].ItemArray.ElementAt(0).ToString();
                            homeWindow.Con.Close();

                            if (detailRek != null)
                            {
                                if (detailRek.IsVisible == false)
                                {
                                    detailRek = new detailReklame(myPath, ((DataRowView)(dataGrid1.SelectedItem)).Row.ItemArray.ElementAt(0).ToString());
                                    detailRek.Visibility = System.Windows.Visibility.Visible;
                                }
                                else
                                {
                                    MessageBox.Show("Anda sudah membuka sebuah window detail", "Error: Multiple Window Opened");
                                }
                            }
                            else
                            {
                                detailRek = new detailReklame(myPath, ((DataRowView)(dataGrid1.SelectedItem)).Row.ItemArray.ElementAt(0).ToString());
                                detailRek.Visibility = System.Windows.Visibility.Visible;
                            }
                        }
                        catch (SqlException sqle)
                        {
                            MessageBox.Show("Ada kesalahan pada koneksi ke server, silakan periksa jaringan.\n\n SQL error code : " + sqle.State, "Error : Connection Not Established");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Anda harus memilih salah satu data", "Error: Null Selection");
                    }
                }
            }
        }

        private void dataGridFoto_Click(object sender, RoutedEventArgs e)
        {
            if (dataGrid1.SelectedIndex >= 0)
            {
                try
                {
                    homeWindow.Con.Open();
                    string myPath = ((DataRowView)(dataGrid1.SelectedItem)).Row.ItemArray.ElementAt(0).ToString();
                    da = new SqlDataAdapter("select PathGambar from Reklame where ID_Reklame = '" + myPath + "'", homeWindow.Con);
                    DataSet ds = new DataSet();
                    da.Fill(ds, "Daftar Path");
                    myPath = ds.Tables["Daftar Path"].Rows[0].ItemArray.ElementAt(0).ToString();
                    System.Diagnostics.Process prc = new System.Diagnostics.Process();
                    prc.StartInfo.FileName = myPath;
                    prc.Start();
                    homeWindow.Con.Close();
                }
                catch (SqlException sqle)
                {
                    MessageBox.Show("Ada kesalahan pada koneksi ke server, silakan periksa jaringan.\n\n SQL error code : " + sqle.State, "Error : Connection Not Established");
                }
            }
        }

        private void dataGridContacts_Click(object sender, RoutedEventArgs e)
        {
            if (dataGrid1.SelectedIndex >= 0)
            {
                contactperson = new cp(((DataRowView)(dataGrid1.SelectedItem)).Row.ItemArray.ElementAt(0).ToString(), ((DataRowView)(dataGrid1.SelectedItem)).Row.ItemArray.ElementAt(2).ToString(), 0);
                contactperson.Visibility = System.Windows.Visibility.Visible;
            }
        }

        private void dataGridTransaksi_Click(object sender, RoutedEventArgs e)
        {
            if (dataGrid1.SelectedIndex >= 0)
            {
                switch (tabel)
                {
                    case GUDANG:
                        LaporanPemakaianBarang pemakaian = new LaporanPemakaianBarang((DataRowView)(dataGrid1.SelectedItem));
                        break;
                    case REKLAME:
                        if (rek == 1)
                        {
                            penyewaan sewa = new penyewaan((DataRowView)(dataGrid1.SelectedItem));
                        }
                        else
                        {
                            MessageBox.Show("Hanya bisa dilakukan pada tabel 'Reklame Kosong'", "Invalid Operation");
                        }
                        break;
                    case PENYEWAAN:
                        if (rek == 1)
                        {
                            PembayaranForm bayar = new PembayaranForm((DataRowView)(dataGrid1.SelectedItem));
                        }
                        else
                        {
                            MessageBox.Show("Hanya bisa dilakukan pada tabel 'Kontrak Aktif'", "Invalid Operation");
                        }
                        break;
                }
            }
            else
            {
                MessageBox.Show("Anda harus memilih salah satu data", "Error: Null Selection");
            }
        }

        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Escape)
            {
                this.Close();
            }
            else if (tabel == REKLAME && dataGrid1.SelectedIndex >= 0 && e.Key == Key.G)
            {
                try
                {
                    homeWindow.Con.Open();
                    string myPath = ((DataRowView)(dataGrid1.SelectedItem)).Row.ItemArray.ElementAt(0).ToString();
                    da = new SqlDataAdapter("select PathGambar from Reklame where ID_Reklame = '" + myPath + "'", homeWindow.Con);
                    DataSet ds = new DataSet();
                    da.Fill(ds, "Daftar Path");
                    myPath = ds.Tables["Daftar Path"].Rows[0].ItemArray.ElementAt(0).ToString();
                    System.Diagnostics.Process prc = new System.Diagnostics.Process();
                    prc.StartInfo.FileName = myPath;
                    prc.Start();
                    homeWindow.Con.Close();
                }
                catch (SqlException sqle)
                {
                    MessageBox.Show("Ada kesalahan pada koneksi ke server, silakan periksa jaringan.\n\n SQL error code : " + sqle.State, "Error : Connection Not Established");
                }
            }
            else if (tabel == PENYEWAAN && dataGrid1.SelectedIndex >= 0 && e.Key == Key.C)
            {
                cp cp = new cp(((DataRowView)(dataGrid1.SelectedItem)).Row.ItemArray.ElementAt(0).ToString(), ((DataRowView)(dataGrid1.SelectedItem)).Row.ItemArray.ElementAt(1).ToString(),0);
                cp.Visibility = System.Windows.Visibility.Visible;
            }
            else if (e.Key == Key.R)
            {
                refresh();
            }
//            else if (e.Key == Key.P)
//            {
//                if (tabel == REKLAME)
//                {
//                    if (rek == 0)
//                    {
//                        try
//                        {
//                            homeWindow.Con.Open();
//                            String text = "Daftar Semua Reklame";
//                            String query;
//                            if (role.Equals("Marketing"))
//                            {
//                                query = @"SELECT ID_Reklame as [ID Reklame], Ukuran, Jenis, Alamat, Kota, Provinsi, 'Rp ' + Convert(varchar(20),dbo.format_currency(PriceList),1) as [Price List] FROM DaftarSemuaReklameM";
//                                if (isFilter)
//                                {
//                                    if (filter[0] == true)
//                                    {
//                                        Console.WriteLine(set.s);
//                                        query = query + " where kota like '%" + set.s + "%'";
//                                    }
//                                    else
//                                    {
//                                        Console.WriteLine("2323");
//                                        query = query + " where provinsi like '%" + set.s + "%'";
//                                    }
//                                }

//                            }
//                            else
//                            {
//                                query = @"SELECT ID_Reklame as [ID Reklame], Ukuran, Jenis, Alamat, Kota, Provinsi, 'Rp ' + Convert(varchar(20),dbo.format_currency(Pajak),1) as Pajak, Convert(varchar(10),Tanggal_Jatuh_Tempo_Pajak,103) as [Tanggal Jatuh Tempo Pajak],
//                                         'Rp ' +Convert(varchar(20),dbo.format_currency(Harga_Sewa_Lokasi),1) as [Harga Sewa Lokasi], 'Rp ' + Convert(varchar(20),dbo.format_currency(Harga_Sewa),1) as [Harga Sewa], 'Rp ' + Convert(varchar(20),dbo.format_currency(PriceList),1) as [Price List] FROM DaftarSemuaReklame";
//                                if (isFilter)
//                                {
//                                    if (filter[0] == true)
//                                    {
//                                        Console.WriteLine(set.s);
//                                        query = query + " where kota like '%" + set.s + "%'";
//                                    }
//                                    else
//                                    {
//                                        Console.WriteLine("2323");
//                                        query = query + " where provinsi like '%" + set.s + "%'";
//                                    }
//                                }
//                            }
//                            da = new SqlDataAdapter(query, homeWindow.Con);
//                            DataSet ds = new DataSet();
//                            da.Fill(ds, text);
//                            ExcelLibrary.DataSetHelper.CreateWorkbook("Testing.xls", ds);
//                            homeWindow.Con.Close();
//                        }
//                        catch (SqlException sqle)
//                        {
//                            MessageBox.Show("Ada kesalahan pada koneksi ke server, silakan periksa jaringan.\n\n SQL error code : " + sqle.State, "Error : Connection Not Established");
//                        }
//                    }
//                }
//            }
        }

        private void topWindow_Closing(object sender, CancelEventArgs e)
        {
            if (Visibility == System.Windows.Visibility.Visible)
            {
                MessageBoxResult choice = MessageBox.Show("Log Out dari tampilan tabel?", "Log Out", MessageBoxButton.OKCancel);
                if (choice == MessageBoxResult.OK)
                {
                    close = true;
                    caution.Close();
                    set.Close();
                    homeWindow.stop = false;
                }
                else
                {
                    e.Cancel = true;
                }
            }
        }

        private void topWindow_Unloaded(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void dataGrid1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
           
        }

        public void refresh()
        {
            SolidColorBrush White = new SolidColorBrush(Color.FromRgb(200, 200, 200));
            SolidColorBrush Black = new SolidColorBrush(Color.FromRgb(0, 0, 0));
            switch (tabel) {
                case REKLAME:
                    if (rek == 0)
                        label6.Content = "Data Seluruh Reklame";
                    else if (rek == 1)
                        label6.Content = "Data Reklame Tidak Sedang Disewa";
                    else if (rek == 2)
                        label6.Content = "Data Reklame Sedang Disewa";
                    break;
                case PENYEWAAN: 
                    if (rek == 0)
                        label6.Content = "Data Seluruh Penyewaan";
                    else if (rek == 1)
                        label6.Content = "Data Penyewaan Aktif";
                    else if (rek == 2)
                        label6.Content = "Data Penyewaan Lampau";
                    break;
                case PEMBAYARAN:
                    label6.Content = "Laporan Pembayaran";
                    break;
                case GUDANG:
                    label6.Content = "Pergudangan";
                    break;
                case PEMBELIAN:
                    label6.Content = "Laporan Pembelian";
                    break;
                case PEMAKAIAN:
                    label6.Content = "Laporan Pemakaian";
                    break;
                case PENGGUNA:
                    label6.Content = "Data Pengguna";
                    break;
                case CP:
                    label6.Content = "Data Contact Person";
                    break;
                case RENCANAPEMBAYARAN:
                    label6.Content = "Rencana Pembayaran";
                    break;
                default:
                    label6.Content = "";
                    break;
            }
 
            if (tabel == PENGGUNA)
            {
                try
                {
                    homeWindow.Con.Open();
                    string text = "Daftar Pengguna";
                    String query = "SELECT username, Nama, Role FROM Pengguna";
                    da = new SqlDataAdapter(query, homeWindow.Con);
                    DataSet ds = new DataSet();
                    da.Fill(ds, text);
                    dataGrid1.ItemsSource = ds.Tables[text].DefaultView;
                    if (dataGrid1.Columns.Count > 0)
                    {
                        for (int i = 0; i < 3; i++)
                        {
                            dataGrid1.Columns[i].HeaderStyle = (Style)Resources["CenterAlignedColumnHeaderStyle"];
                        }
                    }
                    homeWindow.Con.Close();
                }
                catch (SqlException sqle)
                {
                    MessageBox.Show("Ada kesalahan pada koneksi ke server, silakan periksa jaringan.\n\n SQL error code : " + sqle.State, "Error : Connection Not Established");
                }
                detail.Foreground = White;
                foto.Foreground = White;
                contacts.Foreground = White;
                detail.IsEnabled = false;
                foto.IsEnabled = false;
                contacts.IsEnabled = false;

                ubah.Visibility = System.Windows.Visibility.Visible;
                hapus.Visibility = System.Windows.Visibility.Visible;
                ubah.Foreground = Black;
                ubah.IsEnabled = true;
                hapus.Foreground = Black;
                hapus.IsEnabled = true;

                transaksi.Visibility = System.Windows.Visibility.Collapsed;
            }
            else if (tabel == PEMAKAIAN)
            {
                try
                {
                    homeWindow.Con.Open();
                    string text = "Laporan Pemakaian";
                    String query = "SELECT Nama_Barang as [Nama Barang], Jumlah, Convert(varchar(10),b.Tanggal,103) as Tanggal, b.Keterangan, b.id_pemakaian " +
                                    "FROM Menggunakan AS b inner JOIN Daftar_Barang AS c ON b.ID_Barang = c.ID_Barang";
                    if (isFilter)
                    {
                        query = query + set.s;
                    }
                    da = new SqlDataAdapter(query, homeWindow.Con);
                    DataSet ds = new DataSet();
                    da.Fill(ds, text);
                    dataGrid1.ItemsSource = ds.Tables[text].DefaultView;
                    if (dataGrid1.Columns.Count > 0)
                    {
                        for (int i = 0; i < 4; i++)
                        {
                            dataGrid1.Columns[i].HeaderStyle = (Style)Resources["CenterAlignedColumnHeaderStyle"];
                        }
                        dataGrid1.Columns[1].CellStyle = (Style)Resources["RightAlignedCellStyle"];
                    }
                    homeWindow.Con.Close();
                }
                catch (SqlException sqle)
                {
                    MessageBox.Show("Ada kesalahan pada koneksi ke server, silakan periksa jaringan.\n\n SQL error code : " + sqle.State, "Error : Connection Not Established");
                }
                detail.Foreground = White;
                foto.Foreground = White;
                contacts.Foreground = White;
                detail.IsEnabled = false;
                foto.IsEnabled = false;
                contacts.IsEnabled = false;

                ubah.Visibility = System.Windows.Visibility.Visible;
                hapus.Visibility = System.Windows.Visibility.Visible;
                ubah.Foreground = Black;
                ubah.IsEnabled = true;
                hapus.Foreground = Black;
                hapus.IsEnabled = true;

                transaksi.Visibility = System.Windows.Visibility.Collapsed;
            }
            else if (tabel == PEMBELIAN)
            {
                try
                {
                    homeWindow.Con.Open();
                    string text = "Laporan Pembelian";
                    String query = "SELECT b.ID_Laporan as [ID Laporan], b.ID_Barang as [ID Barang], Nama_Barang as [Nama Barang], Jumlah, convert(varchar(10),Tanggal,103) as Tanggal, a.Keterangan, a.username as [Pengisi] " +
                                    "FROM Laporan_Barang AS a INNER JOIN Pembelian AS b ON a.ID_Laporan = b.ID_Laporan JOIN Daftar_Barang AS c ON b.ID_Barang = c.ID_Barang ";
                    if (isFilter)
                    {
                        if (filter[5] == true)
                        {
                            Console.WriteLine(set.s);
                            query = query + " where nama_barang = '" + set.s + "' ORDER BY [ID Laporan]";
                        }
                        else
                        {
                            Console.WriteLine("2323");
                            query = query + set.s + " ORDER BY [ID Laporan]";
                        }
                    }
                    else
                    {
                        query = query + " ORDER BY [ID Laporan]";
                    }
                    da = new SqlDataAdapter(query, homeWindow.Con);
                    DataSet ds = new DataSet();
                    da.Fill(ds, text);
                    dataGrid1.ItemsSource = ds.Tables[text].DefaultView;
                    if (dataGrid1.Columns.Count > 0)
                    {
                        for (int i = 0; i < 7; i++)
                        {
                            dataGrid1.Columns[i].HeaderStyle = (Style)Resources["CenterAlignedColumnHeaderStyle"];
                        }
                        dataGrid1.Columns[3].CellStyle = (Style)Resources["RightAlignedCellStyle"];
                    }
                    homeWindow.Con.Close();
                }
                catch (SqlException sqle)
                {
                    MessageBox.Show("Ada kesalahan pada koneksi ke server, silakan periksa jaringan.\n\n SQL error code : " + sqle.State, "Error : Connection Not Established");
                }
                detail.Foreground = White;
                foto.Foreground = White;
                contacts.Foreground = White;
                detail.IsEnabled = false;
                foto.IsEnabled = false;
                contacts.IsEnabled = false;

                ubah.Visibility = System.Windows.Visibility.Visible;
                hapus.Visibility = System.Windows.Visibility.Visible;
                ubah.Foreground = Black;
                ubah.IsEnabled = true;
                hapus.Foreground = Black;
                hapus.IsEnabled = true;

                transaksi.Visibility = System.Windows.Visibility.Collapsed;
            }
            else if (tabel == GUDANG)
            {
                try
                {
                    homeWindow.Con.Open();
                    string text = "Daftar Barang";
                    String query = "SELECT ID_Barang as [ID Barang], Nama_Barang as [Nama Barang], Total, Keterangan FROM Daftar_Barang";
                    da = new SqlDataAdapter(query, homeWindow.Con);
                    DataSet ds = new DataSet();
                    da.Fill(ds, text);
                    dataGrid1.ItemsSource = ds.Tables[text].DefaultView;
                    if (dataGrid1.Columns.Count > 0)
                    {
                        for (int i = 0; i < 4; i++)
                        {
                            dataGrid1.Columns[i].HeaderStyle = (Style)Resources["CenterAlignedColumnHeaderStyle"];
                        }
                        dataGrid1.Columns[2].CellStyle = (Style)Resources["RightAlignedCellStyle"];
                    }
                    homeWindow.Con.Close();
                }
                catch (SqlException sqle)
                {
                    MessageBox.Show("Ada kesalahan pada koneksi ke server, silakan periksa jaringan.\n\n SQL error code : " + sqle.State, "Error : Connection Not Established");
                }
                detail.Foreground = White;
                foto.Foreground = White;
                contacts.Foreground = White;
                detail.IsEnabled = false;
                foto.IsEnabled = false;
                contacts.IsEnabled = false;

                ubah.Visibility = System.Windows.Visibility.Visible;
                hapus.Visibility = System.Windows.Visibility.Visible;
                ubah.Foreground = Black;
                ubah.IsEnabled = true;
                hapus.Foreground = Black;
                hapus.IsEnabled = true;

                transaksi.Header = "Pakai";
                transaksi.Visibility = System.Windows.Visibility.Visible;
            }
            else if (tabel == PEMBAYARAN)
            {
                try
                {
                    homeWindow.Con.Open();
                    string text = "Daftar Pembayaran";
                    String query = "SELECT ID_Pembayaran as [ID Pembayaran], ID_Penyewaan as [ID Penyewaan], Pembayaran_ke as [Pembayaran ke], Convert(Varchar(10),Tanggal_Pembayaran,103) as [Tanggal Pembayaran], 'Rp ' + Convert(varchar(20),dbo.format_currency(Jumlah_Pembayaran),1) as [Jumlah Pembayaran], No_Invoice as [No Invoice], No_Faktur as [No Faktur] FROM Pembayaran";
                    if (isFilter)
                    {
                        query = query + set.s;
                    }
                    da = new SqlDataAdapter(query, homeWindow.Con);
                    DataSet ds = new DataSet();
                    da.Fill(ds, text);
                    dataGrid1.ItemsSource = ds.Tables[text].DefaultView;
                    if (dataGrid1.Columns.Count > 0)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            dataGrid1.Columns[i].HeaderStyle = (Style)Resources["CenterAlignedColumnHeaderStyle"];
                        }
                        dataGrid1.Columns[2].CellStyle = (Style)Resources["RightAlignedCellStyle"];
                        dataGrid1.Columns[4].CellStyle = (Style)Resources["RightAlignedCellStyle"];
                    }
                    homeWindow.Con.Close();
                }
                catch (SqlException sqle)
                {
                    MessageBox.Show("Ada kesalahan pada koneksi ke server, silakan periksa jaringan.\n\n SQL error code : " + sqle.State, "Error : Connection Not Established");
                }
                detail.Foreground = White;
                foto.Foreground = White;
                contacts.Foreground = White;
                detail.IsEnabled = false;
                foto.IsEnabled = false;
                contacts.IsEnabled = false;

                ubah.Visibility = System.Windows.Visibility.Visible;
                hapus.Visibility = System.Windows.Visibility.Visible;
                ubah.Foreground = Black;
                ubah.IsEnabled = true;
                hapus.Foreground = Black;
                hapus.IsEnabled = true;

                transaksi.Visibility = System.Windows.Visibility.Collapsed;
            }
            else if (tabel == REKLAME)
            {
                if (rek == 0)
                {
                    try
                    {
                        homeWindow.Con.Open();
                        String text = "Daftar Semua Reklame";
                        String query;
                        if (role.Equals("Marketing"))
                        {
                            query = @"SELECT ID_Reklame as [ID Reklame], Ukuran, Jenis, Alamat, Kota, Provinsi, 'Rp ' + Convert(varchar(20),dbo.format_currency(PriceList),1) as [Price List] FROM DaftarSemuaReklameM";
                            if (isFilter)
                            {
                                if (filter[0] == true)
                                {
                                    Console.WriteLine(set.s);
                                    query = query + " where kota like '%" + set.s + "%'";
                                }
                                else
                                {
                                    Console.WriteLine("2323");
                                    query = query + " where provinsi like '%" + set.s + "%'";
                                }
                            }

                        }
                        else
                        {
                            query = @"SELECT ID_Reklame as [ID Reklame], Ukuran, Jenis, Alamat, Kota, Provinsi, 'Rp ' + Convert(varchar(20),dbo.format_currency(Pajak),1) as Pajak, Convert(varchar(10),Tanggal_Jatuh_Tempo_Pajak,103) as [Tanggal Jatuh Tempo Pajak],
                                         'Rp ' +Convert(varchar(20),dbo.format_currency(Harga_Sewa_Lokasi),1) as [Harga Sewa Lokasi], 'Rp ' + Convert(varchar(20),dbo.format_currency(Harga_Sewa),1) as [Harga Sewa], 'Rp ' + Convert(varchar(20),dbo.format_currency(PriceList),1) as [Price List] FROM DaftarSemuaReklame";
                            if (isFilter)
                            {
                                if (filter[0] == true)
                                {
                                    Console.WriteLine(set.s);
                                    query = query + " where kota like '%" + set.s + "%'";
                                }
                                else
                                {
                                    Console.WriteLine("2323");
                                    query = query + " where provinsi like '%" + set.s + "%'";
                                }
                            }
                        }
                        da = new SqlDataAdapter(query, homeWindow.Con);
                        DataSet ds = new DataSet();
                        da.Fill(ds, text);
                        dataGrid1.ItemsSource = ds.Tables[text].DefaultView;
                        if (role.Equals("Marketing"))
                        {
                            if (dataGrid1.Columns.Count > 0)
                            {
                                for (int i = 0; i < 7; i++)
                                {
                                    dataGrid1.Columns[i].HeaderStyle = (Style)Resources["CenterAlignedColumnHeaderStyle"];
                                }
                                dataGrid1.Columns[6].CellStyle = (Style)Resources["RightAlignedCellStyle"];
                            }
                        }
                        else
                        {
                            if (dataGrid1.Columns.Count > 0)
                            {
                                for (int i = 0; i < 11; i++)
                                {
                                    dataGrid1.Columns[i].HeaderStyle = (Style)Resources["CenterAlignedColumnHeaderStyle"];
                                }
                                dataGrid1.Columns[6].CellStyle = (Style)Resources["RightAlignedCellStyle"];
                                dataGrid1.Columns[8].CellStyle = (Style)Resources["RightAlignedCellStyle"];
                                dataGrid1.Columns[9].CellStyle = (Style)Resources["RightAlignedCellStyle"];
                                dataGrid1.Columns[10].CellStyle = (Style)Resources["RightAlignedCellStyle"];
                            }
                        }
                        homeWindow.Con.Close();
                    }
                    catch (SqlException sqle)
                    {
                        MessageBox.Show("Ada kesalahan pada koneksi ke server, silakan periksa jaringan.\n\n SQL error code : " + sqle.State, "Error : Connection Not Established");
                    }
               }
                else if (rek == 1)
                {
                    try
                    {
                        homeWindow.Con.Open();
                        String text = "Daftar Reklame Aktif";
                        String query;
                        if (role.Equals("Marketing"))
                        {
                            query = @"SELECT ID_Reklame as [ID Reklame], Ukuran, Jenis, Alamat, Kota, Provinsi, 'Rp ' + Convert(varchar(20),dbo.format_currency(PriceList),1) as [Price List] FROM DaftarReklameAktifM";
                            if (isFilter)
                            {
                                if (filter[0] == true)
                                {
                                    Console.WriteLine(set.s);
                                    query = query + " where kota like '%" + set.s + "%'";
                                }
                                else
                                {
                                    Console.WriteLine("2323");
                                    query = query + " where provinsi like '%" + set.s + "%'";
                                }
                            }
                        }
                        else
                        {
                            query = @"SELECT ID_Reklame as [ID Reklame], Ukuran, Jenis, Alamat, Kota, Provinsi, 'Rp ' + Convert(varchar(20),dbo.format_currency(Pajak),1) as Pajak, Convert(varchar(10),Tanggal_Jatuh_Tempo_Pajak,103) as [Tanggal Jatuh Tempo Pajak],
                                         'Rp ' +Convert(varchar(20),dbo.format_currency(Harga_Sewa_Lokasi),1) as [Harga Sewa Lokasi], 'Rp ' + Convert(varchar(20),dbo.format_currency(Harga_Sewa),1) as [Harga Sewa], 'Rp ' + Convert(varchar(20),dbo.format_currency(PriceList),1) as [Price List] FROM DaftarReklameAktif";
                            if (isFilter)
                            {
                                if (filter[0] == true)
                                {
                                    Console.WriteLine(set.s);
                                    query = query + " where kota like '%" + set.s + "%'";
                                }
                                else
                                {
                                    Console.WriteLine("2323");
                                    query = query + " where provinsi like '%" + set.s + "%'";
                                }
                            }
                        }
                        da = new SqlDataAdapter(query, homeWindow.Con);
                        DataSet ds = new DataSet();
                        da.Fill(ds, text);
                        dataGrid1.ItemsSource = ds.Tables[text].DefaultView;
                        if (role.Equals("Marketing"))
                        {
                            if (dataGrid1.Columns.Count > 0)
                            {
                                for (int i = 0; i < 7; i++)
                                {
                                    dataGrid1.Columns[i].HeaderStyle = (Style)Resources["CenterAlignedColumnHeaderStyle"];
                                }
                                dataGrid1.Columns[6].CellStyle = (Style)Resources["RightAlignedCellStyle"];
                            }
                        }
                        else
                        {
                            if (dataGrid1.Columns.Count > 0)
                            {
                                for (int i = 0; i < 11; i++)
                                {
                                    dataGrid1.Columns[i].HeaderStyle = (Style)Resources["CenterAlignedColumnHeaderStyle"];
                                }
                                dataGrid1.Columns[6].CellStyle = (Style)Resources["RightAlignedCellStyle"];
                                dataGrid1.Columns[8].CellStyle = (Style)Resources["RightAlignedCellStyle"];
                                dataGrid1.Columns[9].CellStyle = (Style)Resources["RightAlignedCellStyle"];
                                dataGrid1.Columns[10].CellStyle = (Style)Resources["RightAlignedCellStyle"];
                            }
                        }
                        homeWindow.Con.Close();
                    }
                    catch (SqlException sqle)
                    {
                        MessageBox.Show("Ada kesalahan pada koneksi ke server, silakan periksa jaringan.\n\n SQL error code : " + sqle.State, "Error : Connection Not Established");
                    }
                }
                else if (rek == 2)
                {
                    try
                    {
                        homeWindow.Con.Open();
                        String text = "Daftar Reklame Disewa";
                        String query;
                        if (role.Equals("Marketing"))
                        {
                            query = @"SELECT ID_Reklame as [ID Reklame], Ukuran, Jenis, Alamat, Kota, Provinsi, 'Rp ' + Convert(varchar(20),dbo.format_currency(PriceList),1) as [Price List] FROM DaftarReklameDisewaM";
                            if (isFilter)
                            {
                                if (filter[0] == true)
                                {
                                    Console.WriteLine(set.s);
                                    query = query + " where kota like '%" + set.s + "%'";
                                }
                                else
                                {
                                    Console.WriteLine("2323");
                                    query = query + " where provinsi like '%" + set.s + "%'";
                                }
                            }
                        }
                        else
                        {
                            query = @"SELECT ID_Reklame as [ID Reklame], Ukuran, Jenis, Alamat, Kota, Provinsi, 'Rp ' + Convert(varchar(20),dbo.format_currency(Pajak),1) as Pajak, Convert(varchar(10),Tanggal_Jatuh_Tempo_Pajak,103) as [Tanggal Jatuh Tempo Pajak],
                                         'Rp ' +Convert(varchar(20),dbo.format_currency(Harga_Sewa_Lokasi),1) as [Harga Sewa Lokasi], 'Rp ' + Convert(varchar(20),dbo.format_currency(Harga_Sewa),1) as [Harga Sewa], 'Rp ' + Convert(varchar(20),dbo.format_currency(PriceList),1) as [Price List] FROM DaftarReklameDisewa";
                            if (isFilter)
                            {
                                if (filter[0] == true)
                                {
                                    Console.WriteLine(set.s);
                                    query = query + " where kota like '%" + set.s + "%'";
                                }
                                else
                                {
                                    Console.WriteLine("2323");
                                    query = query + " where provinsi like '%" + set.s + "%'";
                                }
                            }
                        }
                        da = new SqlDataAdapter(query, homeWindow.Con);
                        DataSet ds = new DataSet();
                        da.Fill(ds, text);
                        dataGrid1.ItemsSource = ds.Tables[text].DefaultView;
                        if (role.Equals("Marketing"))
                        {
                            if (dataGrid1.Columns.Count > 0)
                            {
                                for (int i = 0; i < 7; i++)
                                {
                                    dataGrid1.Columns[i].HeaderStyle = (Style)Resources["CenterAlignedColumnHeaderStyle"];
                                }
                                dataGrid1.Columns[6].CellStyle = (Style)Resources["RightAlignedCellStyle"];
                            }
                        }
                        else
                        {
                            if (dataGrid1.Columns.Count > 0)
                            {
                                for (int i = 0; i < 11; i++)
                                {
                                    dataGrid1.Columns[i].HeaderStyle = (Style)Resources["CenterAlignedColumnHeaderStyle"];
                                }
                                dataGrid1.Columns[6].CellStyle = (Style)Resources["RightAlignedCellStyle"];
                                dataGrid1.Columns[8].CellStyle = (Style)Resources["RightAlignedCellStyle"];
                                dataGrid1.Columns[9].CellStyle = (Style)Resources["RightAlignedCellStyle"];
                                dataGrid1.Columns[10].CellStyle = (Style)Resources["RightAlignedCellStyle"];
                            }
                        }
                        homeWindow.Con.Close();
                    }
                    catch (SqlException sqle)
                    {
                        MessageBox.Show("Ada kesalahan pada koneksi ke server, silakan periksa jaringan.\n\n SQL error code : " + sqle.State, "Error : Connection Not Established");
                    }
                }
                detail.Foreground = Black;
                foto.Foreground = Black;
                contacts.Foreground = White;
                detail.IsEnabled = true;
                foto.IsEnabled = true;
                contacts.IsEnabled = false;
                if (role.Equals("Keuangan") || role.Equals("Marketing"))
                {
                    ubah.Visibility = System.Windows.Visibility.Collapsed;
                    hapus.Visibility = System.Windows.Visibility.Collapsed;
                }
                else if (role.Equals("Manager"))
                {

                    ubah.Visibility = System.Windows.Visibility.Visible;
                    hapus.Visibility = System.Windows.Visibility.Visible;
                    ubah.Foreground = Black;
                    hapus.Foreground = Black;
                    ubah.IsEnabled = true;
                    hapus.IsEnabled = true;
                }

                if (role.Equals("Marketing"))
                {
                    transaksi.Visibility = System.Windows.Visibility.Collapsed;
                }
                else
                {
                    transaksi.Header = "Kontrak";
                    transaksi.Visibility = System.Windows.Visibility.Visible;
                }
            }
            else if (tabel == PENYEWAAN)
            {
                if (rek == 0)
                {
                    try
                    {
                        homeWindow.Con.Open();
                        string text = "Daftar Semua Penyewaan";
                        String query = "SELECT a.ID_Penyewaan as [ID Penyewaan], b.ID_Reklame as [ID Reklame], a.Nama_klien as [Nama Klien], 'Rp ' + Convert(varchar(20),dbo.format_currency(a.Total_Harga),1) as [Total Harga], CONVERT(VARCHAR(10), a.Tanggal_Mulai, 103) AS [Tanggal Mulai], CONVERT(VARCHAR(10), a.Tanggal_Selesai, 103) AS [Tanggal Selesai], a.Keterangan FROM Penyewaan AS a JOIN Menyewa AS b on a.ID_Penyewaan = b.ID_Penyewaan";
                        if (isFilter)
                        {
                            if (filter[2] == true)
                            {
                                Console.WriteLine(set.s);
                                query = query + set.s;
                            }
                            else
                            {
                                Console.WriteLine("2323");
                                query = query + set.s;
                            }
                        }
                        da = new SqlDataAdapter(query, homeWindow.Con);
                        DataSet ds = new DataSet();
                        da.Fill(ds, text);
                        dataGrid1.ItemStringFormat = "{0:d}";
                        dataGrid1.ItemsSource = ds.Tables[text].DefaultView;
                        if (dataGrid1.Columns.Count > 0)
                        {
                            for (int i = 0; i < 7; i++)
                            {
                                dataGrid1.Columns[i].HeaderStyle = (Style)Resources["CenterAlignedColumnHeaderStyle"];
                            }
                            dataGrid1.Columns[3].CellStyle = (Style)Resources["RightAlignedCellStyle"];
                        }
                        homeWindow.Con.Close();
                    }
                    catch (SqlException sqle)
                    {
                        MessageBox.Show("Ada kesalahan pada koneksi ke server, silakan periksa jaringan.\n\n SQL error code : " + sqle.State, "Error : Connection Not Established");
                    }
                }
                else if (rek == 1)
                {
                    try
                    {
                        homeWindow.Con.Open();
                        string text = "Daftar Penyewaan Aktif";
                        String query = "SELECT ID_Penyewaan as [ID Penyewaan], ID_Reklame as [ID Reklame], Nama_klien as [Nama Klien], 'Rp ' + Convert(varchar(20),dbo.format_currency(Total_Harga),1) as [Total Harga], CONVERT(VARCHAR(10), Tanggal_Mulai, 103) AS [Tanggal Mulai], CONVERT(VARCHAR(10), Tanggal_Selesai, 103) AS [Tanggal Selesai], Keterangan FROM PenyewaanAktif";
                        if (isFilter)
                        {
                            if (filter[2] == true)
                            {
                                Console.WriteLine(set.s);
                                query = query + set.s;
                            }
                            else
                            {
                                Console.WriteLine("2323");
                                query = query + set.s;
                            }
                        }
                        da = new SqlDataAdapter(query, homeWindow.Con);
                        DataSet ds = new DataSet();
                        da.Fill(ds, text);
                        dataGrid1.ItemsSource = ds.Tables[text].DefaultView;
                        if (dataGrid1.Columns.Count > 0)
                        {
                            for (int i = 0; i < 7; i++)
                            {
                                dataGrid1.Columns[i].HeaderStyle = (Style)Resources["CenterAlignedColumnHeaderStyle"];
                            }
                            dataGrid1.Columns[3].CellStyle = (Style)Resources["RightAlignedCellStyle"];
                        }
                        homeWindow.Con.Close();
                    }
                    catch (SqlException sqle)
                    {
                        MessageBox.Show("Ada kesalahan pada koneksi ke server, silakan periksa jaringan.\n\n SQL error code : " + sqle.State, "Error : Connection Not Established");
                    }
                }
                else if (rek == 2)
                {
                    try
                    {
                        homeWindow.Con.Open();
                        string text = "Daftar Penyewaan Lampau";
                        String query = "SELECT ID_Penyewaan as [ID Penyewaan], ID_Reklame as [ID Reklame], Nama_klien as [Nama Klien], 'Rp ' + Convert(varchar(20),dbo.format_currency(Total_Harga),1) as [Total Harga], CONVERT(VARCHAR(10), Tanggal_Mulai, 103) AS [Tanggal Mulai], CONVERT(VARCHAR(10), Tanggal_Selesai, 103) AS [Tanggal Selesai], Keterangan FROM PenyewaanLampau";
                        if (isFilter)
                        {
                            if (filter[2] == true)
                            {
                                Console.WriteLine(set.s);
                                query = query + set.s;
                            }
                            else
                            {
                                Console.WriteLine("2323");
                                query = query + set.s;
                            }
                        }
                        da = new SqlDataAdapter(query, homeWindow.Con);
                        DataSet ds = new DataSet();
                        da.Fill(ds, text);
                        dataGrid1.ItemsSource = ds.Tables[text].DefaultView;
                        if (dataGrid1.Columns.Count > 0)
                        {
                            for (int i = 0; i < 7; i++)
                            {
                                dataGrid1.Columns[i].HeaderStyle = (Style)Resources["CenterAlignedColumnHeaderStyle"];
                            }
                            dataGrid1.Columns[3].CellStyle = (Style)Resources["RightAlignedCellStyle"];
                        }
                        homeWindow.Con.Close();
                    }
                    catch (SqlException sqle)
                    {
                        MessageBox.Show("Ada kesalahan pada koneksi ke server, silakan periksa jaringan.\n\n SQL error code : " + sqle.State, "Error : Connection Not Established");
                    }
                }
                detail.Foreground = Black;
                foto.Foreground = White;
                contacts.Foreground = Black;
                detail.IsEnabled = true;
                foto.IsEnabled = false;
                contacts.IsEnabled = true;

                ubah.Visibility = System.Windows.Visibility.Visible;
                hapus.Visibility = System.Windows.Visibility.Visible;
                ubah.Foreground = Black;
                ubah.IsEnabled = true;
                hapus.Foreground = Black;
                hapus.IsEnabled = true;

                transaksi.Header = "Pembayaran"; 
                transaksi.Visibility = System.Windows.Visibility.Visible;
            }
        }

        private void Konfigurasi_Click(object sender, RoutedEventArgs e)
        {
            //KonfigurasiTanggal konf = new KonfigurasiTanggal();
            //konf.Visibility = System.Windows.Visibility.Visible;
        }

        private void Reklame_MouseEnter(object sender, MouseEventArgs e)
        {
            if (sender.Equals(Reklame))
            {
                Reklame.Foreground = Brushes.Black;
            }
            else if (sender.Equals(Reklame_Aktif))
            {
                Reklame_Aktif.Foreground = Brushes.Black;
            }
            else if (sender.Equals(Reklame_Disewa))
            {
                Reklame_Disewa.Foreground = Brushes.Black;
            }
            else if (sender.Equals(Semua_Reklame))
            {
                Semua_Reklame.Foreground = Brushes.Black;
            }
            else if (sender.Equals(Penyewaan))
            {
                Penyewaan.Foreground = Brushes.Black;
            }
            else if (sender.Equals(Semua_Penyewaan))
            {
                Semua_Penyewaan.Foreground = Brushes.Black;
            }
            else if (sender.Equals(Penyewaan_Aktif))
            {
                Penyewaan_Aktif.Foreground = Brushes.Black;
            }
            else if (sender.Equals(Penyewaan_Lampau))
            {
                Penyewaan_Lampau.Foreground = Brushes.Black;
            }
            else if (sender.Equals(Pembayaran))
            {
                Pembayaran.Foreground = Brushes.Black;
            }
            else if (sender.Equals(Laporan_Pemakaian))
            {
                Laporan_Pemakaian.Foreground = Brushes.Black;
            }
            else if (sender.Equals(Laporan_Pembelian))
            {
                Laporan_Pembelian.Foreground = Brushes.Black;
            }
            else if (sender.Equals(Gudang))
            {
                Gudang.Foreground = Brushes.Black;
            }
            else if (sender.Equals(Pengguna))
            {
                Pengguna.Foreground = Brushes.Black;
            }
            else if (sender.Equals(Tambah_Baru))
            {
                Tambah_Baru.Foreground = Brushes.Black;
            }
            else if (sender.Equals(Ubah_))
            {
                Ubah_.Foreground = Brushes.Black;
            }
            else if (sender.Equals(Hapus_))
            {
                Hapus_.Foreground = Brushes.Black;
            }
            else if (sender.Equals(Backup_))
            {
                Backup_.Foreground = Brushes.Black;
            }
            else if (sender.Equals(Restore_))
            {
                Restore_.Foreground = Brushes.Black;
            }
        }

        private void Reklame_MouseLeave(object sender, MouseEventArgs e)
        {
            if (sender.Equals(Reklame))
            {
                Reklame.Foreground = Brushes.White;
            }
            else if (sender.Equals(Reklame_Aktif))
            {
                Reklame_Aktif.Foreground = Brushes.White;
            }
            else if (sender.Equals(Reklame_Disewa))
            {
                Reklame_Disewa.Foreground = Brushes.White;
            }
            else if (sender.Equals(Semua_Reklame))
            {
                Semua_Reklame.Foreground = Brushes.White;
            }
            else if (sender.Equals(Penyewaan))
            {
                Penyewaan.Foreground = Brushes.White;
            }
            else if (sender.Equals(Semua_Penyewaan))
            {
                Semua_Penyewaan.Foreground = Brushes.White;
            }
            else if (sender.Equals(Penyewaan_Aktif))
            {
                Penyewaan_Aktif.Foreground = Brushes.White;
            }
            else if (sender.Equals(Penyewaan_Lampau))
            {
                Penyewaan_Lampau.Foreground = Brushes.White;
            }
            else if (sender.Equals(Pembayaran))
            {
                Pembayaran.Foreground = Brushes.White;
            }
            else if (sender.Equals(Laporan_Pemakaian))
            {
                Laporan_Pemakaian.Foreground = Brushes.White;
            }
            else if (sender.Equals(Laporan_Pembelian))
            {
                Laporan_Pembelian.Foreground = Brushes.White;
            }
            else if (sender.Equals(Gudang))
            {
                Gudang.Foreground = Brushes.White;
            }
            else if (sender.Equals(Pengguna))
            {
                Pengguna.Foreground = Brushes.White;
            }
            else if (sender.Equals(Tambah_Baru))
            {
                Tambah_Baru.Foreground = Brushes.White;
            }
            else if (sender.Equals(Ubah_))
            {
                Ubah_.Foreground = Brushes.White;
            }
            else if (sender.Equals(Hapus_))
            {
                Hapus_.Foreground = Brushes.White;
            }
            else if (sender.Equals(Backup_))
            {
                Backup_.Foreground = Brushes.White;
            }
            else if (sender.Equals(Restore_))
            {
                Restore_.Foreground = Brushes.White;
            }
        }

        private void mainWindow_KeyDown(object sender, KeyEventArgs e)
        {
            
        }
    }
}
